<%@ page language="java" import="java.util.*,bookstore.database.pojo.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
CustomerAddrDAO cusDao =  new CustomerAddrDAO();
Customer customer = (Customer)session.getAttribute("customer");
CustomerAddr cusAddr = null;
String totalPrice = "";
String name = "";
String addr = "";
String tel = "";
if(customer == null) {
	request.getRequestDispatcher("login.jsp").forward(request,response);
}
else {
	cusAddr = cusDao.findByCusEmail(customer.getEmail());
	totalPrice = ((Double)session.getAttribute("totalprice")).toString();
	if(cusAddr == null) {
		request.getRequestDispatcher("orderModify.jsp").forward(request,response);
	}
	else {
		name = cusAddr.getRealName();
		addr = cusAddr.getAddr();
		tel = cusAddr.getTel();
	}
}


Map<String, Map<String, Integer>> cart = (Map<String, Map<String, Integer>>) 
	session.getAttribute("cart");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>我mai 订单确认</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="/css/my.css">
	<script type="text/javascript">
	//跳转到地址修改页面
function returnOrderModify() {

	window.open("orderModify.jsp", "_self");
}
	function makeOrder() {

	window.open("makeOrder.do", "_self");
}
</script>

  </head>
  
  <body>
    <table width="80%" border="0" align="center">
  <tr>
    <td><jsp:include flush="true" page="head.jsp"></jsp:include></td>
  </tr>
  <tr>
    <td><table width="100%" border="1" bordercolor="#33CCFF">
      <tr>
        <td colspan="4" class="style5">检查订单<hr/></td>
      </tr>
      <tr>
        <td width="70%" colspan="3">用户名：<%=customer.getCustomerName() %></td>
        <td bgcolor="#6699FF"><div align="center">
          <input type="submit" name="Submit2" value="修改发货信息" onclick="returnOrderModify();"/>
          <input type="submit" name="Submit" value="订单确认" onclick="makeOrder();"/>
        </div></td>
      </tr>
      <tr>
        <td colspan="3">收件人：<%=name %> </td>
        <td rowspan="3" class="style6">总计金额：￥<%=totalPrice %></td>
      </tr>
      <tr>
        <td colspan="3">地址：<%=addr %></td>
        </tr>
      <tr>
        <td colspan="3">联系电话：<%=tel %><hr/></td>
        </tr>
      <tr>
        <td colspan="4"><div align="center" class="style1">商品详情</div></td>
      </tr>
      <tr>
        <td width="25%"><div align="center">商品名称</div></td>
        <td width="25%"><div align="center">卖家</div></td>
        <td width="25%"><div align="center">单价</div></td>
        <td width="25%"><div align="center">数量</div></td>
      </tr>
      <%
      Iterator it = cart.keySet().iterator();
				while (it.hasNext()) {
					String isbn = (String) it.next();
					Map<String, Integer> seller = cart.get(isbn);
					Iterator it2 = seller.keySet().iterator();
					while (it2.hasNext()) {
						String id = (String) it2.next();
						//int int_id = Integer.parseInt(id);
						java.math.BigDecimal b_id = new java.math.BigDecimal(id);
						//获取数量
						int number = seller.get(id);
						//获取价格
						String price = new SaleTableDAO().findByIsbnAndSelId(isbn,id);
						//获取书名
						Book book = new BookDAO().findById(isbn);
						String bookName = book.getBname();
						//获取卖家用户名
						Seller b_seller = new SellerDAO().findById(b_id);
						Customer seller_customer = b_seller.getCustomer();
						String customer_name = seller_customer.getCustomerName();
						String url = "removeBook.do?removeisbn="+ isbn +"&sellerid="+ id;
			
			%> 
      <tr>
        <td><div align="center"><%=bookName %></div></td>
        <td><div align="center"><%=customer_name %></div></td>
        <td><div align="center">￥<%=price %></div></td>
        <td><div align="center"><%=number %></div></td>
      </tr>
    <%}} %>
    </table></td>
  </tr>
  <tr>
    <td><jsp:include flush="true" page="tail.jsp"></jsp:include></td>
  </tr>
</table>
  </body>
</html>
